<?php

define('IN_ECS', true);
require('chinese.php');

require(dirname(dirname(__FILE__)) . '/includes/init.php');
require(ROOT_PATH . 'myplug/includes/lib_order.php');




$sql = "select * from " .$ecs ->table('order_info')." where order_id=".$_GET['order_id'];
$re = $db->getRow($sql);


//鍦板潃
$_CFG['shop_address']=iconv('UTF-8', 'GB2312', $_CFG['shop_address']);

//鍚嶇О
$_CFG['shop_name']=iconv('UTF-8', 'GB2312', $_CFG['shop_name']);

//鐢佃瘽
$_CFG['service_phone']=iconv('UTF-8', 'GB2312', $_CFG['service_phone']);

/* $re['consignee']= iconv('GB2312', 'UTF-8', $re['consignee']);  */
$re['consignee']= iconv('UTF-8', 'GB2312', $re['consignee']);
$re['mobile']= iconv('UTF-8', 'GB2312', $re['mobile']);
$re['riqi']=date("Y-m-d  H : m : s", $re['add_time']);

$re['jintian']=date("Y-m-d", time());

$sql = "SELECT concat( IFNULL(c.region_name, ' '),   
        IFNULL(p.region_name, ''),   
        IFNULL(t.region_name, ''),   
        IFNULL(d.region_name, '')) AS region " .  
        " FROM " . $ecs->table('region') . " c, " . $ecs->table('region') . " p, " . $ecs->table('region') . " t, " . $ecs->table('region') . " d  
        WHERE c.`region_id`='".$re['country']."'  
        AND p.`region_id`='".$re['province']."'  
        AND t.`region_id`='".$re['city']."'  
        AND d.`region_id`='".$re['district']."'";  
  
$re['region'] = $db->getOne($sql); 

$re['region']=iconv('UTF-8', 'GB2312', $re['region']);
$re['address']=iconv('UTF-8', 'GB2312', $re['address']);

$goods_list = order_goods($re['order_id']);




$i=0;
$pdf=new PDF_Chinese();
$pdf->AddGBFont();
$pdf->AddPage();
$pdf->SetFont('GB','',20);
$pdf->SetFontSize(12);








show_text(100, 17, "璁㈠崟璇︽儏");


/* $pdf->Ln(10);
show_text(5, 35, "鐢ㄦ埛鍚? ".$re['consignee']); */


$pdf->Ln(20);
show_text(5, 42, "鑱旂郴浜? ".$re['consignee']);


$pdf->Ln(30);
show_text(5, 49, "鐢佃瘽: ".$re['mobile']."  ".$re['tel']);


$pdf->Ln(40);
show_text(5, 56, "鍦板潃锛?.$re['region'].$re['address']);


$pdf->Ln(50);
show_text(5, 63, "璁㈠崟鏃ユ湡: ".$re['riqi']);


$pdf->Line(5, 70, 200, 70);

$pdf->Ln(10);
show_text(10, 77, "缂栧彿");
show_text(40, 77, "鍟嗗搧鍚嶇О");
show_text(100, 77, "鏁伴噺");
/* show_text(120, 77, "鍗曚綅"); */
show_text(140, 77, "鍗曚环");
show_text(180, 77, "鏄庣粏鎬讳环");


$y = 0;
foreach($goods_list as $k=>$v){
	$i++;
$pdf->Ln(10);
show_text(10, 77+$i*7, $v['goods_id']);
$v['goods_name']=iconv('UTF-8', 'GB2312', $v['goods_name']);
show_text(40, 77+$i*7, $v['goods_name']);
show_text(100, 77+$i*7, $v['goods_number']);
/* show_text(120, 77+$i*7, 'PSC'); */
show_text(140, 77+$i*7, $v['goods_price']);
show_text(180, 77+$i*7, $v['subtotal']);
}

$i=$i-1;

$pdf->Line(5, 91+$i*7, 200, 91+$i*7);
$pdf->Ln(10);
show_text(10, 97+$i*7, "鎬昏");
show_text(180, 97+$i*7, "".$re['goods_amount']);


show_text(10, 104+$i*7, "浼樻儬");
show_text(180, 104+$i*7, "- ".$re['discount']);


show_text(10, 111+$i*7, "鍚堣");
show_text(180, 111+$i*7, "".$re['order_amount']);






$pdf->AcceptPageBreak();
$pdf->SetAutoPageBreak(TRUE, 10);
$pdf->Output();



function show_text($left, $top,$content){
	global $pdf,$y;
	$page_header=270;
	if($top > $page_header){
		if($top-($page_header*$y) > $page_header){
			$pdf->AddPage();
			$y++;
		}
		$top=$top-$page_header;
	}
	$pdf->Text($left, $top, $content);
	
}

function show_image($str, $left, $top , $width , $height , $type){
	
	global $pdf,$y;
	$page_header=250;
	if($top > $page_header){
		if($top-($page_header*$y) > $page_header){
			$pdf->AddPage();
			$y++;
		}
		$top=$top-$page_header;
	}
	
	/* echo "<pre>";
	print_r($top);
	exit("!!!"); */
	//$pdf->Text($left, $top, $content);
	$pdf->Image($str, $left, $top , $width , $height , $type);
	
}
?>
